<template>

	<view>

		<view
			style="text-align: left;clear: both; font-size: 30rpx; height: 60rpx;  padding-top: 15rpx;font-weight: bold">
			教材</view>
		<SelectButton name="bookVersion" :dataSource="bookVersionDataSource" @buttonClickEvent = "buttonClickEventHander"></SelectButton>
		<view
			style="text-align: left;clear: both; font-size: 30rpx; height: 60rpx;  padding-top: 15rpx;font-weight: bold">
			年级</view>
		<SelectButton name="grade" :dataSource="gradeDataSource" @buttonClickEvent = "buttonClickEventHander"></SelectButton>
		<view
			style="text-align: left;clear: both; font-size: 30rpx; height: 60rpx;  padding-top: 15rpx;font-weight: bold">
			学期</view>
		<SelectButton name="term" :dataSource="termDataSource" @buttonClickEvent = "buttonClickEventHander"></SelectButton>

		<view style="clear: both; margin-top: 130rpx;">
			<u-button style="display: inline-block; width: 360rpx;" @click="cancelClick" type="default">取消
			</u-button>
			<u-button style="display: inline-block; width: 360rpx;margin-left: 5px;" @click="okClick"  type="primary">确定
			</u-button>
		</view>
	</view>
</template>

<script>
	import SelectButton from '@/pages/index/select-button'
	import LocalDataSource from '@/common/LocalDataSource'
	export default {
		components: {
			SelectButton
		},

		props: {
		},
		data() {
			return {
				bookVersionDataSource: [],
				gradeDataSource: [],
				termDataSource: [],
				bookVersion:'',
				grade:'',
				term:'',
				userInfo:{}
			}
		},
		created() {
			
			this.bookVersionDataSource = JSON.parse(JSON.stringify(LocalDataSource.bookVersionDataSource))
			this.gradeDataSource = JSON.parse(JSON.stringify(LocalDataSource.gradeDataSource))
			this.termDataSource = JSON.parse(JSON.stringify(LocalDataSource.termDataSource))
		},
		
		
		methods: {
			loadPage() {
				this.userInfo = JSON.parse(JSON.stringify(this.$store.getters.userInfo))
				if(this.userInfo.bookVersion!=undefined && this.userInfo.bookVersion!='' && this.userInfo.bookVersion!=null)
				{
					this.bookVersionDataSource.forEach((item,idex)=>{
						if(item.code == this.userInfo.bookVersion)
						{
							item.checked = 1
						}
						else
						{
							item.checked = 0
						}
						
					})
				}
				
				if(this.userInfo.bookVersion!=undefined && this.userInfo.bookVersion!='' && this.userInfo.bookVersion!=null)
				{
					this.gradeDataSource.forEach((item,idex)=>{
						if(item.code == this.userInfo.grade)
						{
							item.checked = 1
						}
						else{
							item.checked = 0
						}
						
					})
				}
				
				if(this.userInfo.bookVersion!=undefined && this.userInfo.bookVersion!='' && this.userInfo.bookVersion!=null)
				{
					this.termDataSource.forEach((item,idex)=>{
						if(item.code == this.userInfo.term)
						{
							item.checked = 1
						}
						else{
							item.checked = 0
							
						}
						
					})
					
				}
				
			},
			cancelClick(){
				this.$emit("cancelClickEvent")
			},
			okClick(){
				if(this.userInfo.bookVersion == ''){
					this.$toast("请选择教材")
					return false
				}
				if(this.userInfo.grade == ''){
					this.$toast("请选择年级")
					return false
				}
				if(this.userInfo.term == ''){
					this.$toast("请选择学期")
					return false
				}
				this.$emit("okClickEvent",this.userInfo)
			},
			buttonClickEventHander(obj){
				const app = this
				if(obj.name == "bookVersion"){
					app.bookVersionDataSource.forEach((item,index)=>{
						if(item.code == obj.code)
						{
							item.checked = 1
							app.userInfo.bookVersion = item.code
						}
						else{
							item.checked = 0
						}
						
					})
				}
				
				if(obj.name == "grade"){
					app.gradeDataSource.forEach((item,index)=>{
						if(item.code == obj.code)
						{
							item.checked = 1
							app.userInfo.grade = item.code
						}
						else{
							item.checked = 0
						}
						
					})
					
					
					
				}
				if(obj.name == "term"){
					app.termDataSource.forEach((item,index)=>{
						if(item.code == obj.code)
						{
							item.checked = 1
							app.userInfo.term = item.code
						}
						else{
							item.checked = 0
						}
						
					})
				}
			}
		}

	}
</script>

<style>

</style>
